#include <iostream>
#include <memory.h>
using namespace std;

struct node {
	int w;
	int l, r;
	int p;
};

node T[105];
bool vis[105];

int calc(int x, int d) {
	if (vis[x]) return 0;
	vis[x] = 1;
	int res = d * T[x].w;
	res += calc(T[x].l, d + 1);
	res += calc(T[x].r, d + 1);
	res += calc(T[x].p, d + 1);
	return res;
}

int main() {
	int n;
	cin >> n;
	T[1].p = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> T[i].w >> T[i].l >> T[i].r;
		T[T[i].l].p = i;
		T[T[i].r].p = i;
	}

	int ans = 0x3fffffff;
	for (int x = 1; x <= n; ++x) {
		memset(vis, 0, sizeof(vis));
		vis[0] = 1;
		ans = min(ans, calc(x, 0));
	}

	cout << ans << endl;

	return 0;
}